package com.fitvita.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.fitvita.common.annotation.Log;
import com.fitvita.common.core.controller.BaseController;
import com.fitvita.common.core.domain.AjaxResult;
import com.fitvita.common.enums.BusinessType;
import com.fitvita.domain.ResTerminal;
import com.fitvita.service.IResTerminalService;
import com.fitvita.common.utils.poi.ExcelUtil;
import com.fitvita.common.core.page.TableDataInfo;

/**
 * 管理Controller
 * 
 * @author hao
 * @date 2024-03-03
 */
@RestController
@RequestMapping("/terminal/terminal")
public class ResTerminalController extends BaseController
{
    @Autowired
    private IResTerminalService resTerminalService;

    /**
     * 查询管理列表
     */
    @PreAuthorize("@ss.hasPermi('terminal:terminal:list')")
    @GetMapping("/list")
    public TableDataInfo list(ResTerminal resTerminal)
    {
        startPage();
        List<ResTerminal> list = resTerminalService.selectResTerminalList(resTerminal);
        return getDataTable(list);
    }

    /**
     * 导出管理列表
     */
    @PreAuthorize("@ss.hasPermi('terminal:terminal:export')")
    @Log(title = "管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ResTerminal resTerminal)
    {
        List<ResTerminal> list = resTerminalService.selectResTerminalList(resTerminal);
        ExcelUtil<ResTerminal> util = new ExcelUtil<ResTerminal>(ResTerminal.class);
        util.exportExcel(response, list, "管理数据");
    }

    /**
     * 获取管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('terminal:terminal:query')")
    @GetMapping(value = "/{IMEI}")
    public AjaxResult getInfo(@PathVariable("IMEI") String IMEI)
    {
        return success(resTerminalService.selectResTerminalByIMEI(IMEI));
    }

    /**
     * 新增管理
     */
    @PreAuthorize("@ss.hasPermi('terminal:terminal:add')")
    @Log(title = "管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ResTerminal resTerminal)
    {
        return toAjax(resTerminalService.insertResTerminal(resTerminal));
    }

    /**
     * 修改管理
     */
    @PreAuthorize("@ss.hasPermi('terminal:terminal:edit')")
    @Log(title = "管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ResTerminal resTerminal)
    {
        return toAjax(resTerminalService.updateResTerminal(resTerminal));
    }

    /**
     * 删除管理
     */
    @PreAuthorize("@ss.hasPermi('terminal:terminal:remove')")
    @Log(title = "管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{IMEIs}")
    public AjaxResult remove(@PathVariable String[] IMEIs)
    {
        return toAjax(resTerminalService.deleteResTerminalByIMEIs(IMEIs));
    }
}
